package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.ShopService;
import com.lanchetech.bean.request.*;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.KdzsCallBackResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.*;
import com.lanchetech.common.exception.ResultCodeException;
import com.lanchetech.entity.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@Api(value = "门店管理", tags = "门店管理")
@RequestMapping("/api/shop")
@RestController
public class ShopController {

    @Autowired
    ShopService shopService;

    @OperatorLog("编辑门店")
    @ApiOperation("编辑门店")
    @PreAuthorize("hasAuthority('shop.index.edit.auth')")
    @PostMapping("/editShop")
    public BaseResp editShop(@RequestBody Shop req) {
        return shopService.editShop(req);
    }

    @OperatorLog("编辑门店平台服务费率")
    @ApiOperation("编辑门店平台服务费率")
    @PreAuthorize("hasAuthority('shop.index.edit.auth')")
    @PostMapping("/editShopServiceRate")
    public BaseResp editShopServiceRate(@RequestBody Shop req) {
        return shopService.editShopServiceRate(req);
    }

    @ApiOperation("获取门店分页")
    @PreAuthorize("hasAuthority('shop.index')")
    @PostMapping("/getShopPage")
    public ResultData<BasePageResp<ShopVO>> getShopPage(@RequestBody PageReq req) {
        return shopService.getShopPage(req);
    }

    @ApiOperation("获取门店详情")
    @GetMapping("/getShopDetail")
    public ResultData<Shop> getShopDetail(@RequestParam("id") Long id) {
        return shopService.getShopDetail(id);
    }

    @OperatorLog("删除门店")
    @ApiOperation("删除门店")
    @PreAuthorize("hasAuthority('shop.index.edit.auth')")
    @GetMapping("/deleteShop")
    public BaseResp deleteShop(@RequestParam("id") Long id) {
        return shopService.deleteShop(id);
    }

    @OperatorLog("设置门店店长")
    @ApiOperation("设置门店店长")
    @PreAuthorize("hasAuthority('shop.index.edit.auth')")
    @GetMapping("/editShopUser")
    public BaseResp editShopUser(@RequestParam("id") Long id, @RequestParam("phone") String phone) {
        return shopService.editShopUser(id, phone);
    }

    @OperatorLog("重置商户超级管理员密码")
    @ApiOperation("重置商户超级管理员密码")
    @PreAuthorize("hasAuthority('shop.index.edit.auth')")
    @GetMapping("/resetMerchantPassword")
    public BaseResp resetMerchantPassword(@RequestParam("shopId") Long shopId) {
        return shopService.resetMerchantPassword(shopId);
    }

    @OperatorLog("设置门店老板")
    @ApiOperation("设置门店老板")
    @PreAuthorize("hasAuthority('shop.index.edit.auth')")
    @GetMapping("/editShopBoss")
    public BaseResp editShopBoss(@RequestParam("id") Long id, @RequestParam("phone") String phone, @RequestParam("name") String name, @RequestParam("idCard") String idCard) {
        return shopService.editShopBoss(id, phone, name, idCard);
    }

    @OperatorLog("设置商家推荐人")
    @ApiOperation("设置商家推荐人")
    @PreAuthorize("hasAuthority('shop.index.edit.auth')")
    @GetMapping("/createShopInvite")
    public BaseResp createShopInvite(@RequestParam("id") Long id, @RequestParam("phone") String phone) {
        return shopService.createShopInvite(id, phone);
    }

    @OperatorLog("编辑门店预约设置")
    @ApiOperation("编辑门店预约设置")
    @PreAuthorize("hasAuthority('shop.appointment-setting.edit.auth')")
    @PostMapping("/editAppointmentSetting")
    public BaseResp editAppointmentSetting(@RequestBody AppointmentSetting req) {
        return shopService.editAppointmentSetting(req);
    }

    @ApiOperation("获取商品预约设置详情")
    @GetMapping("/getAppointmentSettingBySpuId")
    public ResultData<AppointmentSetting> getAppointmentSettingBySpuId(@RequestParam("spuId") Long spuId) {
        return shopService.getAppointmentSettingBySpuId(spuId);
    }

    @ApiOperation("获取门店预约设置分页")
    @PreAuthorize("hasAuthority('shop.appointment-setting')")
    @PostMapping("/getAppointmentSettingPage")
    public ResultData<BasePageResp<AppointmentSettingVO>> getAppointmentSettingPage(@RequestBody PageReq req) {
        return shopService.getAppointmentSettingPage(req);
    }

    @OperatorLog("审核活动报名")
    @ApiOperation("审核活动报名")
    @PreAuthorize("hasAuthority('shop.enrollment.audit.auth')")
    @PostMapping("/auditActivityRegister")
    public BaseResp auditActivityRegister(@RequestBody ActivityRegister activityRegister) {
        return shopService.auditActivityRegister(activityRegister);
    }

    @OperatorLog("删除活动报名")
    @ApiOperation("删除活动报名")
    @PreAuthorize("hasAuthority('shop.enrollment.audit.auth')")
    @GetMapping("/deleteActivityRegister")
    public BaseResp deleteActivityRegister(@RequestParam("id") Long id) {
        return shopService.deleteActivityRegister(id);
    }

    @ApiOperation("获取活动报名分页")
    @PreAuthorize("hasAuthority('shop.enrollment')")
    @PostMapping("/getActivityRegisterPage")
    public ResultData<BasePageResp<ActivityRegisterVO>> getActivityRegisterPage(@RequestBody PageReq req) {
        return shopService.getActivityRegisterPage(req);
    }

    @ApiOperation("获取行业分类分页")
    @PreAuthorize("hasAuthority('shop.species')")
    @PostMapping("/getIndustryList")
    public ResultData<BasePageResp<IndustryVO>> getIndustryList(@RequestBody PageReq req) {
        return shopService.getIndustryList(req);
    }

    @ApiOperation("获取行业分类")
    @GetMapping("/getIndustry")
    public ResultData<List<IndustryVO>> getIndustry() {
        return shopService.getIndustry();
    }

    @OperatorLog("编辑行业分类")
    @ApiOperation("编辑行业分类")
    @PreAuthorize("hasAuthority('shop.species.edit.auth')")
    @PostMapping("/editIndustry")
    public BaseResp editIndustry(@RequestBody Industry industry) {
        return shopService.editIndustry(industry);
    }

    @OperatorLog("删除行业分类")
    @ApiOperation("删除行业分类")
    @PreAuthorize("hasAuthority('shop.species.edit.auth')")
    @GetMapping("/deleteIndustry")
    public BaseResp deleteIndustry(@RequestParam("id") Long id) {
        return shopService.deleteIndustry(id);
    }

    @ApiOperation("获取行业类目一级列表")
    @GetMapping("/getIndustryFirstList")
    public ResultData<List<IndustryIdAndNameVO>> getIndustryFirstList(@AuthenticationPrincipal Admin admin) {
        return shopService.getIndustryFirstList(admin);
    }

    @ApiOperation("获取行业类目二级列表")
    @PostMapping("/getIndustrySecondList")
    public ResultData<List<IndustryIdAndNameVO>> getIndustrySecondList(@RequestBody PageReq req) {
        return shopService.getIndustrySecondList(req);
    }

    @OperatorLog("编辑通知模版")
    @ApiOperation("编辑通知模版")
    @PostMapping("/editAnnouncement")
    public BaseResp editAnnouncement(@RequestBody Announcement req) {
        return shopService.editAnnouncement(req);
    }

    @ApiOperation("获取通知模版详情")
    @GetMapping("/getAnnouncementDetail")
    public ResultData<Announcement> getAnnouncementDetail(@RequestParam("id") Long id) {
        return shopService.getAnnouncementDetail(id);
    }

    @OperatorLog("删除通知模版")
    @ApiOperation("删除通知模版")
    @GetMapping("/deleteAnnouncement")
    public BaseResp deleteAnnouncement(@RequestParam("id") Long id) {
        return shopService.deleteAnnouncement(id);
    }

    @OperatorLog("发送模版")
    @ApiOperation("发送模版")
    @PostMapping("/sendAnnouncement")
    public BaseResp sendAnnouncement(@RequestBody AnnouncementReq req) {
        return shopService.sendAnnouncement(req);
    }

    @ApiOperation("获取通知模版分页")
    @PostMapping("/getAnnouncementPage")
    public ResultData<BasePageResp<Announcement>> getAnnouncementPage(@RequestBody AnnouncementPageReq req) {
        return shopService.getAnnouncementPage(req);
    }

    @ApiOperation("获取商户通知分页")
    @PostMapping("/getShopAnnouncementPage")
    public ResultData<BasePageResp<ShopAnnouncementVO>> getShopAnnouncementPage(@RequestBody ShopAnnouncementPageReq req) {
        return shopService.getShopAnnouncementPage(req);
    }

    @ApiOperation("获取通知模版列表")
    @GetMapping("/getShopAnnouncementList")
    public ResultData<List<Announcement>> getShopAnnouncementList() {
        return shopService.getShopAnnouncementList();
    }

    @ApiOperation("获取老板推荐店铺分页")
    @PostMapping("getBossInviteShopPage")
    public ResultData<BasePageResp<BossInviteShopVO>> getBossInviteShopPage(@RequestBody BossInviteShopReq req) {
        return shopService.getBossInviteShopPage(req);
    }

    @ApiOperation("获取老板身份分页")
    @PostMapping("getBossIdentityPage")
    public ResultData<BasePageResp<BossIdentityVO>> getBossIdentityPage(@RequestBody BossIdentityReq req) {
        return shopService.getBossIdentityPage(req);
    }

    @ApiOperation("快递助手回调")
    @PostMapping("/kuaidizsCallBack")
    public KdzsCallBackResp kuaidizsCallBack(@RequestParam Map<String, String> params) {
        return shopService.kuaidizsCallBack(params);
    }
}
